#include <iostream>
#include "TcpServer.h"
#include "TcpConn.h"

#ifdef MULTI_POLLER
#include "MultiPoller.h"
#else
#include "Poller.h"
#endif

int main() 
{
#ifdef MULTI_POLLER
    MultiPoller<2> poller;
#else
    Poller poller;
#endif
    TcpServer server1(&poller);

    server1.Start(port: 8989, cb: [](TcpConn::Ptr conn)-> void {
        std::cout << "[server1]New connection established\n";
        conn->SetReadCallback(cb: [conn]()-> void {
            std::cout << "Received: "<< conn->GetAllData() << std::endl
            conn->Send(buf: "HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\nHello !", len: 43);
        });
    }};

    TcpServer server2(&poller);
    server2.Start(port: 8990, cb: [](TcpConn::Ptr conn)->void {
        std::cout << "[server2]New connection established\n";
        conn->SetReadCallback(cb: [conn]()-> void {
            std::cout << "Received: "<< conn->GetDataUntilCrLf() <<std::endl
            conn->Send(buf: "Hello World!\r\n", len: 15);
        });
    });
    
    while(true) {
        std::string input;
        std::getline(std::cin, input);
        if(input == "quit") {
            break;
        }
        
    }

    std::exit(0);
    return 0;
}